/**
 * Copyright 2013 yangming.liu<liuyangming@gmail.com>.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, see <http://www.gnu.org/licenses/>.
 */
package org.bytesoft.openjta.archive;

import org.bytesoft.openjta.resource.Terminator;

public class TerminatorArchive extends ResourceArchive {
	private static final long serialVersionUID = 1L;

	private boolean containsLocalResource;
	private Terminator terminator;
	private boolean cleanupStarted;
	private BooleanResult cleanupResult;

	public boolean isContainsLocalResource() {
		return containsLocalResource;
	}

	public void setContainsLocalResource(boolean containsLocalResource) {
		this.containsLocalResource = containsLocalResource;
	}

	public boolean isCleanupSuccess() {
		return this.cleanupStarted && BooleanResult.positive.equals(this.cleanupResult);
	}

	public Terminator getTerminator() {
		return terminator;
	}

	public void setTerminator(Terminator terminator) {
		this.terminator = terminator;
	}

	public boolean isCleanupStarted() {
		return cleanupStarted;
	}

	public void setCleanupStarted(boolean cleanupStarted) {
		this.cleanupStarted = cleanupStarted;
	}

	public BooleanResult getCleanupResult() {
		return cleanupResult;
	}

	public void setCleanupResult(BooleanResult cleanupResult) {
		this.cleanupResult = cleanupResult;
	}

	public void setCleanupResult(boolean success) {
		if (success) {
			this.cleanupResult = BooleanResult.positive;
		} else {
			this.cleanupResult = BooleanResult.negative;
		}
	}

	public int hashCode() {
		return this.terminator == null ? 31 : this.terminator.hashCode();
	}

	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		} else if (!this.getClass().isInstance(obj)) {
			return false;
		}
		TerminatorArchive that = (TerminatorArchive) obj;
		if (this.terminator == that.terminator) {
			return true;
		} else if (this.terminator == null || that.terminator == null) {
			return false;
		} else {
			return this.terminator.equals(that.terminator);
		}
	}
}
